﻿namespace Randomness
{
    using MediaPortal.Configuration;
    using MediaPortal.Dialogs;
    using MediaPortal.GUI.Library;
    using MediaPortal.Profile;
    using myLog;
    using System;

    internal class settings
    {
        private int getNumberMenu(numbertype menType, string heading)
        {
            int num;
            GUIDialogMenu window = (GUIDialogMenu)GUIWindowManager.GetWindow(0x7dc);
            window.Reset();
            window.ShowQuickNumbers = false;
            window.SetHeading(heading);
            if (menType == numbertype.percentage)
            {
                for (num = 5; num <= 100; num += 5)
                {
                    window.Add(num.ToString());
                }
                window.DoModal(GUIWindowManager.ActiveWindow);
                myLog.logger.log("numbermenu selected label " + window.SelectedLabel.ToString() + " returning " + ((window.SelectedLabel * 5)).ToString());
                return ((window.SelectedLabel + 1) * 5);
            }
            for (num = 1; num <= 10; num++)
            {
                window.Add(num.ToString());
            }
            window.DoModal(GUIWindowManager.ActiveWindow);
            myLog.logger.log("numbermenu selected label " + window.SelectedLabel.ToString());
            return (window.SelectedLabel + 1);
        }

        public void ShowSettingsDialog()
        {
            int num8;
            GUIDialogMenu window = (GUIDialogMenu)GUIWindowManager.GetWindow(0x7dc);
            window.Reset();
            window.SetHeading("Smart Random Settings");
            Settings settings = new Settings(Config.GetFolder(Config.Dir.Config) + "/MediaPortal.xml", true);
            int num = settings.GetValueAsInt("mvid", "noPlayWeight", 6);
            int num2 = settings.GetValueAsInt("mvid", "recentWeight", 6);
            int num3 = settings.GetValueAsInt("mvid", "topWeight", 6);
            int num4 = settings.GetValueAsInt("mvid", "recentPercent", 20);
            int num5 = settings.GetValueAsInt("mvid", "noPlayPercent", 20);
            int num6 = settings.GetValueAsInt("mvid", "topPercent", 20);
            int num7 = settings.GetValueAsInt("mvid", "totalPercent", 20);
            window.Add("No Play Weight - " + num.ToString());
            window.Add("Recent Weight - " + num2.ToString());
            window.Add("Score Weight - " + num3.ToString());
            window.Add("No Play Percentage - " + num5.ToString());
            window.Add("Recent Percentage - " + num4.ToString());
            window.Add("Score Percentage - " + num6.ToString());
            window.Add("Total Percentage - " + num7.ToString());
            window.DoModal(GUIWindowManager.ActiveWindow);
            switch (window.SelectedLabel)
            {
                case 0:
                    num8 = this.getNumberMenu(numbertype.oneTen, "Select weight to give videos with no plays");
                    if (num8 == -1)
                    {
                        num8 = num;
                    }
                    settings.SetValue("mvid", "noPlayWeight", num8);
                    this.ShowSettingsDialog();
                    break;

                case 1:
                    num8 = num2;
                    num8 = this.getNumberMenu(numbertype.oneTen, "Select weight to give recent videos");
                    if (num8 == -1)
                    {
                        num8 = num2;
                    }
                    settings.SetValue("mvid", "recentWeight", num8);
                    this.ShowSettingsDialog();
                    break;

                case 2:
                    num8 = num3;
                    num8 = this.getNumberMenu(numbertype.oneTen, "Select weight to give Top 100 videos");
                    if (num8 == -1)
                    {
                        num8 = num3;
                    }
                    settings.SetValue("mvid", "topWeight", num8);
                    this.ShowSettingsDialog();
                    break;

                case 3:
                    num8 = num5;
                    num8 = this.getNumberMenu(numbertype.percentage, "Select percentage to sample no play videos.");
                    settings.SetValue("mvid", "noPlayPercent", num8);
                    this.ShowSettingsDialog();
                    break;

                case 4:
                    num8 = num4;
                    num8 = this.getNumberMenu(numbertype.percentage, "Select percentage to sample of recent videos");
                    if (num8 == -1)
                    {
                        num8 = num4;
                    }
                    settings.SetValue("mvid", "recentPercent", num8);
                    this.ShowSettingsDialog();
                    break;

                case 5:
                    num8 = num6;
                    num8 = this.getNumberMenu(numbertype.percentage, "Select percentage to sample of Top Rated videos");
                    if (num8 == -1)
                    {
                        num8 = num6;
                    }
                    settings.SetValue("mvid", "topPercent", num8);
                    this.ShowSettingsDialog();
                    break;

                case 6:
                    num8 = num7;
                    num8 = this.getNumberMenu(numbertype.percentage, "Select total percentage of videos");
                    if (num8 == -1)
                    {
                        num8 = num7;
                    }
                    settings.SetValue("mvid", "totalPercent", num8);
                    this.ShowSettingsDialog();
                    break;
            }
            settings.Dispose();
        }

        private enum numbertype
        {
            percentage,
            oneTen
        }
    }
}

